home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / APPL_INI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-14  |  5.5 KB  |  167 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <UNISTD.H>
  9. #include <FILESYS.H>
  10. #include <OSBIND.H>
  11. #include <MINTBIND.H>
  12. #include <stdio.h>
  13. #include "XA_GLOBL.H"
  14. #include "XA_TYPES.H"
  15. #include "XA_DEFS.H"
  16. #include "XA_CODES.H"
  17. #include "K_DEFS.H"
  18. #include "KERNAL.H"
  19.  
  20. /* Note: since XA_handler now properly loads the global base register,
  21.     `far' data is no longer needed! <mk> */
  22. /* (Except if the 64 K limit is reached, of course...) */
  23.  
  24. /* <beta4>
  25.    New approach here - the XaAES.cmd pipe is no longer a global handle
  26.    (there were problems re-opening it after a shutdown), so we have to open it
  27.    especially - this is in fact the only place it's used. Clients introduce themselves
  28.    via the XaAES.cmd pipe, then do everything else via their individual pipes.
  29.   <craig>
  30. */
  31.  
  32. char r_pipe_name[50];
  33. char r_fmt[]="u:\\pipe\\XaClnt.%d\0";
  34. short new_client_contrl[]={XA_NEW_CLIENT,0,0,0,0};
  35. short client_exit_contrl[]={XA_CLIENT_EXIT,0,0,0,0};
  36. AESPB new_client_pb;
  37. K_CMD_PACKET new_client_packet;
  38.  
  39. /*
  40.     Application initialise - appl_init()
  41.     Remember that this executes under the CLIENT pid, not the kernal.
  42.     (Hence the semaphore locking on the routine)
  43. */
  44. unsigned long XA_appl_init(short clnt_pid, AESPB *pb)
  45. {
  46.     XA_CLIENT *client=Pid2Client(clnt_pid);
  47.     short drv;
  48.     long AES_in_pipe;
  49.  
  50.     Psemaphore(2,APPL_INIT_SEMAPHORE,-1L);
  51.     
  52. /* In XaAES, AESid==MiNT process id : this makes error tracking easier */
  53.     pb->intout[0]=clnt_pid;
  54.  
  55. #if EMULATE_AES4_1
  56.     pb->globl[0]=0x0410;        /* Try to emulate AES4.1 */
  57. #else
  58.     pb->globl[0]=0x0140;        /* Try to emulate AES 1.4 (TOS 1.04/1.06) */
  59.                                 /* (this is Martin's idea - I'm not sure about it myself, 
  60.                                     so I've made it a compile time option */                                    
  61. #endif
  62.  
  63.     pb->globl[1]=-1;            /* Unlimited applications (well, not really) */
  64.     pb->globl[2]=clnt_pid;        /* appid==pid */
  65.     pb->globl[5]=0;
  66.     pb->globl[6]=0;
  67.     pb->globl[7]=0;
  68.     pb->globl[8]=0;
  69.     pb->globl[9]=0;
  70.     pb->globl[10]=display.planes;
  71.     pb->globl[11]=0;
  72.     pb->globl[12]=0;
  73.     pb->globl[13]=display.c_max_h;        /* AES4.0 extensions */
  74.     pb->globl[14]=4;
  75.  
  76.     client->globl_ptr=pb->globl;        /* Preserve the pointer to the global array */
  77.                                             /* so we can fill in the resource address later */
  78.     
  79.     if (client->clnt_pipe_rd)
  80.     {
  81.         DIAGS(("client pipe already opened (handle=%d) in appl_init\n",client->clnt_pipe_rd));
  82.         Psemaphore(3,APPL_INIT_SEMAPHORE,0);
  83.         return XAC_DONE;
  84.     }
  85.  
  86.     AES_in_pipe=Fopen("u:\\pipe\\XaAES.cmd",O_RDWR);
  87.  
  88. /* Create a new client reply pipe */
  89.     sprintf(r_pipe_name,r_fmt,clnt_pid);
  90.     
  91.     /* For some reason, a pipe created with mode O_RDONLY does *not* go
  92.         away when all users have closed it (or were terminated) - apparently
  93.         a MiNT bug?!?! */
  94.     /* BTW: if *this* end of the pipe was created with O_RDWR, the *other*
  95.         end cannot be O_WRONLY, or strange things will happen when the
  96.         pipe is closed... */
  97.     client->clnt_pipe_rd=Fopen(r_pipe_name,O_CREAT|O_RDWR);    /* Client's end of pipe */
  98.     
  99.     pb->globl[12]=client->clnt_pipe_rd;    /* XaAES extension */
  100.  
  101. /* Get the client's home directory (where it was started) - we use this later to load
  102.     resource files, etc */
  103.     drv=Dgetdrv();
  104.     client->home_path[0]=(char)drv+'a';
  105.     client->home_path[1]=':';
  106.     client->home_path[2]='\\';
  107.     Dgetcwd(client->home_path+3,drv+1,(short)sizeof(client->home_path)-4);
  108.  
  109. /* Reset the AES messages pending list for our new application */
  110.     client->msg=NULL;
  111. /* No widgets have action pending on a new app */
  112.     client->widget_active=NULL;
  113. /* Initially, client isn't waiting on any event types */
  114.     client->waiting_for=0;
  115.     client->waiting_pb=NULL;
  116. /* Initial settings for the clients mouse cursor */
  117.     client->client_mouse=ARROW;        /* Default client mouse cursor is an arrow */
  118.     client->client_mouse_form=NULL;
  119.  
  120. /* Build a 'register new client' packet and send it to the kernal
  121.    - the kernal will respond by opening it's end of the reply pipe ready for use */
  122.     new_client_pb.contrl=new_client_contrl;
  123.     new_client_packet.pid=clnt_pid;                /* client pid */
  124.     new_client_packet.cmd=AESCMD_STD;            /* no reply */
  125.     new_client_packet.pb=&new_client_pb;        /* pointer to AES parameter block */
  126.  
  127.     Fwrite(AES_in_pipe, sizeof(K_CMD_PACKET), &new_client_packet);    /* Send packet */
  128.  
  129.     Fclose(AES_in_pipe);
  130.  
  131.     Psemaphore(3,APPL_INIT_SEMAPHORE,0);
  132.  
  133.     return XAC_BLOCK;    /* Block the client until the server get's it's act together */
  134. }
  135.  
  136.  
  137. /*
  138.     Application Exit
  139.     This also executes under the CLIENT pid.
  140.     This closes the clients end of the reply pipe, and sends a message to the kernal
  141.     to tell it to close it's end as well - the client tidy-up is done at the server 
  142.     end when the XA_CLIENT_EXIT op-code is recieved, not here.
  143. */
  144. unsigned long XA_appl_exit(short clnt_pid, AESPB *pb)
  145. {
  146.     short *intout=pb->intout;
  147.     XA_CLIENT *client= Pid2Client(clnt_pid);
  148.  
  149.     intout[0]=clnt_pid;                        /* Which process are we? It'll be a client pid */
  150.  
  151. /* Build a 'client is exiting' packet and send it to the kernal
  152.    - the kernal will respond by closing it's end of the clients reply pipe. */
  153.     new_client_pb.contrl=client_exit_contrl;
  154.     new_client_packet.pid=intout[0];            /* client pid */
  155.     new_client_packet.cmd=AESCMD_STD;            /* no reply */
  156.     new_client_packet.pb=&new_client_pb;        /* pointer to AES parameter block */
  157.  
  158.     Fwrite(client->clnt_pipe_rd, sizeof(K_CMD_PACKET), &new_client_packet);    /* Send packet */
  159.  
  160. #if 0
  161.     Fclose(client->clnt_pipe_rd);    /* Close the client end of client reply pipe */
  162.     client->clnt_pipe_rd=0;
  163. #endif
  164.  
  165.     return XAC_BLOCK;                /* Block the client until the server has closed down it's end of things */
  166. }
  167.